home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 07511000 / var0888.dms / var0888.adf / WoManD / man / C_Library / fscanf < prev    next >
Text File  |  1992-09-19  |  4KB  |  109 lines

  1. FSCANF(1)                   C LIBRARY FUNCTIONS                    FSCANF(1)
  2.  
  3. NAME
  4.      fscanf, scanf, sscanf - formatted input functions.
  5.  
  6. SYNOPSIS
  7.      int fscanf(const char *cntrl_string, ...);
  8.  
  9.      int scanf(FILE *fp, const char *cntrl_string, ...);
  10.  
  11.      int sscanf(char *s, const char *cntrl_string, ...);
  12.  
  13. INCLUDE FILE
  14.      stdio.h
  15.  
  16. DESCRIPTION
  17.      fscanf() reads text from the file associated with fp, converts the
  18.           characters according to the conversion specification in
  19.           cntrl_string, placing the values in memory at the addresses
  20.           specified by the other arguments. fscanf() returns the number of
  21.           conversion accomplished, or EOF if an end-of-file is encountered
  22.           or if no conversion have occurred.
  23.  
  24.      scanf() is equivalent to fscanf(stdin, , ...).
  25.  
  26.      sscanf() is equivalent to scanf(), except that it reads from the string
  27.           s instead of a file.
  28.  
  29.      Each of these functions convert formats, and read their arguments
  30.      under control of the format string. The format is a character string
  31.      which contains blanks or tabs which are ignored, Ordinary character
  32.      (excluding %) which are expected to match the next non blank character
  33.      of the input stream, and conversion specifications, each of which causes
  34.      conversion of a string into variable pointed to by the corresponding
  35.      argument.
  36.  
  37.      Each conversion specification is of the form
  38.  
  39.           %*n(l|L|h)t
  40.  
  41.      where all the parameters are optional apart from the type t.
  42.  
  43.      - * : if present, it means that the conversion should be performed, but
  44.            the result should not be stored. Their should be no argument
  45.            pointer for that conversion.
  46.  
  47.      - n : an integer that specifies the maximal scan width.
  48.  
  49.      - l/L/h : indicates that the pointer refers to a long or short type of
  50.              object. For integers object (d,i,o,u,x,X), l means that the
  51.              object must be stored in a long integer. For float objects
  52.              (e,E,g,G,f), it means that the object must be stored in a
  53.              double. L can precede e,E,g,G or f to indicated that the
  54.              converted value must be stored in a long double.
  55.  
  56.      - t : c   : any char, converted to (arg: char *).
  57.            d,i : optionally signed decimal integer (arg: int *).
  58.            u   : optionally signed decimal integer (arg: unsigned int *).
  59.            o   : optionally signed octal integer (arg: unsigned int *).
  60.            x,X : optionally signed hexadecimal integer (arg: unsigned int *).
  61.            s   : a sequence of non white space characters. (arg: char *).
  62.                   A string ends with a BLANK SPACE or '\n'.
  63.    - f,e,E,g,G : optionally signed floating point number. (arg :float *).
  64.            p   : what is produced by %p in printf() (usually an unsigned
  65.                   hexadecimal number)                 (arg : void * *).
  66.            n   : the corresponding argument is a pointer to an integer
  67.                   into which the number of character read so far is put.
  68.            %   : %% prints the '%' sign.
  69.          [...] : Matches the longest non-empty string of input character
  70.                   that only contains characters listed inside the brackets.
  71.                   (arg : char *).
  72.          [^..] : Matches the longest non-empty string of input character
  73.                   that contains any characters but those listed inside the
  74.                   brackets. (arg : char *).
  75. EXAMPLES
  76.    - if a file containing
  77.  
  78.           4 5 , Disregard_this, x This_is_a_string
  79.  
  80.      is read by the following call to fscanf(),
  81.  
  82.       int i;
  83.       short j;
  84.       char *str,Buff[125];
  85.       FILE *fp;
  86.  
  87.       /* open the file */
  88.  
  89.       fscanf(fp,"%d %hd , %*s %% %c %4s %s ",&i,&j,str,Buff);
  90.  
  91.    then, the variable will contain the following:
  92.  
  93.       i => 4, j => 5, str => This, Buff => _is_a_string .
  94.  
  95.    - If the following program
  96.  
  97.      main()
  98.      { char mantissa[20],exponent[20];
  99.  
  100.        scanf("%[^Ee]%[1234567890]",mantissa,exponent);
  101.        printf("%se%s\n",mantissa,exponent);
  102.  
  103.      }
  104.  
  105.      is given 123e4 in input, it will print 123E4 on stdout.
  106.  
  107. SEE ALSO
  108.    open(), close(), getc(), printf().
  109.